--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit 9c156fe38182dbc06c8b78979573c64ceef20a07
Parents : a8d8e19
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-07T15:21:21-05:00
feat(build-backend): add function to remove Python bytecode artifacts and set PYTHONDONTWRITEBYTECODE for builds on macOS
Changes
Diff
diff --git a/scripts/build-backend.js b/scripts/build-backend.js
index 3570e9e2..e121953f 100755
--- a/scripts/build-backend.js
+++ b/scripts/build-backend.js
@@ -18,6 +18,27 @@ function getFiles(dir, fileList = []) {
return fileList;
}
+function stripPythonBytecodeArtifacts(dir) {
+ if (!fs.existsSync(dir)) return;
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
+ for (const ent of entries) {
+ const full = path.join(dir, ent.name);
+ if (ent.isDirectory()) {
+ if (ent.name === "__pycache__") {
+ fs.rmSync(full, { recursive: true, force: true });
+ } else {
+ stripPythonBytecodeArtifacts(full);
+ }
+ } else if (ent.name.endsWith(".pyc") || ent.name.endsWith(".pyo")) {
+ const stem = ent.name.replace(/\.pyc$/i, "").replace(/\.pyo$/i, "");
+ const siblingPy = path.join(dir, `${stem}.py`);
+ if (fs.existsSync(siblingPy)) {
+ fs.unlinkSync(full);
+ }
+ }
+ }
+}
+
function generateManifest(buildDir, manifestPath) {
console.log("Generating backend integrity manifest...");
const files = getFiles(buildDir);
@@ -69,6 +90,7 @@ try {
...process.env,
CX_FREEZE_TARGET_NAME: targetName,
CX_FREEZE_BUILD_EXE: buildDirRelative,
+ PYTHONDONTWRITEBYTECODE: "1",
};
const cmdParts = pythonCmd.trim().split(/\s+/).filter(Boolean);
@@ -100,6 +122,9 @@ try {
}
if (fs.existsSync(buildDir)) {
+ if (isDarwin) {
+ stripPythonBytecodeArtifacts(buildDir);
+ }
const manifestPath = path.join(buildDir, "backend-manifest.json");
generateManifest(buildDir, manifestPath);
} else {
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────